package com.qfedu.controller;

import com.github.pagehelper.PageInfo;
import com.qfedu.entity.Driverinfo;
import com.qfedu.service.DriverService;
import com.qfedu.util.PageHelperUtil;
import com.qfedu.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * projectName: logistics
 * author: CGY
 * time: 2020/10/6 11:05
 * description:
 */
@RestController
@RequestMapping("/driverInfo")
public class DriverController {
    @Autowired
    private DriverService driverService;

    @RequestMapping("/selectAllId.do")
    @ResponseBody
    public Result selectAllId(){
        List<Driverinfo> list =  driverService.selectAllId();
        return Result.success(list);
    }
    @RequestMapping("/add.do")
    public Result add(Driverinfo driverinfo){
        Result ret = driverService.addDriver(driverinfo);
        return ret;
    }
    @RequestMapping("/selectAllByPage.do")
    public PageHelperUtil selectAllByPage(Integer pageNum, Integer limit){
        PageInfo pageInfo = driverService.selectAll();

        return PageHelperUtil.success(pageInfo.getTotal(),pageInfo.getList());
    }

    @RequestMapping("/selectById.do")
    public Result selectById(String id){
        Result ret = driverService.selectDriverById(id);
        return ret;
    }

    @RequestMapping("/update.do")
    public Result update(Driverinfo driverinfo){
        Result ret = driverService.updateDriver(driverinfo);
        return ret;
    }

    @RequestMapping("/delete.do")
    public Result delete(String id){
        Result ret = driverService.delete(id);
        return ret;
    }
}
